package com.ewzj.bigdata.mvp.ui.widget;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.ewzj.bigdata.R;
import com.jess.arms.utils.ArmsUtils;
import com.mylhyl.circledialog.BaseCircleDialog;

/**
 * Author:zhangjing
 * Time:2018/3/14  下午3:09
 * Name: this is InputDialog
 * Email:zhangjingworkmol@163.com
 */

public class InputDialog extends BaseCircleDialog implements View.OnClickListener{
    private  Addlistener addlistener;
    InputDialog dialogFragment;
    public static InputDialog getInstance() {
        InputDialog dialogFragment = new InputDialog();
        dialogFragment.setBackgroundColor(Color.parseColor("#ccfcfcfc"));
        dialogFragment.setCanceledBack(false);
        dialogFragment.setCanceledOnTouchOutside(false);
        dialogFragment.setGravity(Gravity.CENTER);
        dialogFragment.setWidth(0.8f);
        return dialogFragment;
    }
    public interface Addlistener{
        void add(String title);
    }

    public Addlistener getAddlistener() {
        return addlistener;
    }

    public void setAddlistener(Addlistener addlistener) {
        this.addlistener = addlistener;
    }

    @Override
    public View createView(Context context, LayoutInflater inflater, ViewGroup container) {
        View view= inflater.inflate(R.layout.dialog_collect_create, container, false);
        view.findViewById(R.id.tv_cancell).setOnClickListener(this);
        view.findViewById(R.id.tv_confirm).setOnClickListener(this);
        return view;
    }
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        getView().findViewById(R.id.tv_cancell).setOnClickListener(this);
        getView().findViewById(R.id.tv_confirm).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        String text=((EditText)getView().findViewById(R.id.et_name)).getText().toString();
        switch (view.getId()){
            case R.id.tv_cancell:
                dismiss();
                break;
            case R.id.tv_confirm:
                if (addlistener!=null){
                    if (TextUtils.isEmpty(text)){
                        ArmsUtils.snackbarText("标题不能为空");
                        return;
                    }else {
                        addlistener.add(text);
                        dismiss();
                    }

                }
                break;
        }
    }
}
